home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
tcisam.zip
/
IREADP.C
< prev
next >
Wrap
Text File
|
1987-08-21
|
2KB
|
52 lines
/*
* IREADP.C - read previous
*
* Copyright (c) 1987, Jim Mischel
* Modifications:
*
* 08/13/87 - jim - original coding
*/
#include "inxdefs.h"
/*
* iread_prev() - return the previous record in sequence. The file must be
* started using istart() before this routine is called. If successful
* returns 0 with data record at destin. At top of file, EOF is returned.
* Any other errors return status. In the case of EOF or error, the data at
* destin is unchanged.
*
* This routine assumes there is enough space at 'dest' to store the entire
* data record.
*/
int iread_prev(void *d, void *dest)
{
df_rec *db_control = (df_rec *)d;
char *destin = (char *)dest;
if (db_control->df_flags & DF_TOF)
return(EOF); /* already reached top of file */
/*
* if this is not the first read after starting the file, get the
* prevfious index record into the buffer.
*/
if (!(db_control->df_flags & DF_START)) {
if (iget_prev(db_control,&db_control->df_nxt_buff))
return(EOF);
memcpy(&db_control->df_nxt_buff,&db_control->df_inx_buff,sizeof(inx_rec));
}
else
db_control->df_flags &= ~DF_START; /* reset first read flag */
/* get the data record */
if (iread_dat(db_control,db_control->df_nxt_buff.if_dat_ptr))
return(ierrno);
db_control->df_flags &= ~DF_EOF; /* clear end-of-file flag */
db_control->df_flags &= ~DF_DELETE;
/* copy the data record from data buffer into user's area */
memcpy(destin,db_control->df_dat_buff,db_control->df_rec_size);
return(0);
} /* iread_prev */